package pl.prv.polanie.client.panels.lists;

import pl.prv.polanie.client.dialogs.CreateSubgroupTypeDialog;
import pl.prv.polanie.client.dto.CSSubgroupTypeDTO;
import pl.prv.polanie.client.dto.CSVSubgroupTypeDTO;
import pl.prv.polanie.client.model.Cache;
import pl.prv.polanie.client.model.ViewDataProvider;
import pl.prv.polanie.client.widgets.table.TableSubgroupTypes;

import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Widget;

public class SubgroupTypesList extends ObjectsList {

	TableSubgroupTypes tableSubgroupTypes= new TableSubgroupTypes(this);
	
	public SubgroupTypesList() {
		
		CSSubgroupTypeDTO[] ls = Cache.getAllSubgroupTypes();
		
		add(tableSubgroupTypes);
		
		
		for (int i = 0; i < ls.length; i++) {
			
			CSSubgroupTypeDTO cs = ls[i];
			CSVSubgroupTypeDTO csv = ViewDataProvider.getCSVSubgroupType(cs);
			
			tableSubgroupTypes.addRow(cs, csv);
		}
		
		
		addRecordButton.addClickListener(new ClickListener(){
			public void onClick(Widget sender) {
				CreateSubgroupTypeDialog cstd = new CreateSubgroupTypeDialog(SubgroupTypesList.this, null); 
				cstd.center();
			}
		});
		
		removeSelectedRecordButton.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {
				tableSubgroupTypes.removeSelectedSubgroupTypeFromTable();
			}
		});
		
		setupButtons();
	}

	
	public void addCSSubgroupType(CSSubgroupTypeDTO csSubgroupType) {
		tableSubgroupTypes.saveOrUpdateSubgroupTypeInTable(csSubgroupType);
	}
	
	public void removeSelectdCSLecturer() {
		tableSubgroupTypes.removeSelectedSubgroupTypeFromTable();
	}
	
}
